package dennis;

import java.util.ArrayList;
import java.util.Scanner;

public class CommandInput {
	
	//public static String buffer;
	public static boolean Importance = false;
	static String command;
	static ArrayList<String> output = new ArrayList<String>();
	
	/*public static void main(String[] args) {
		// Reads a single line from the console 
		// and stores into name variable
		
		// uncomment the below three lines to take in commands.
		//Scanner in = new Scanner(System.in);
		//command = in.nextLine(); //nextline for strings 
		//in.close();            
		
		//comment away the line below to take in from keyboard
		command = "+ * l:sports jogging with David @ 1900 # 120312 $ Park";
		
		CommandInput newInput = new CommandInput(command);
		newInput.parseCmd();
		newInput.out2console();
		
	}*/
	/*start of modification, may 27 - defeng, also replaced all System.out.println() with output.add()
	 * 
	 */
	
	//constructor
	public CommandInput(String ainput){
		command = ainput;
	}
	
	public static void parseCmd(){
		String[] temp;
		//delimiter
				String delimiter = " ";
				//given string will be split by the argument delimiter provided.
				temp = command.split(delimiter);
				
				if(temp[0].equals("+") || temp[0].equals("+*"))
					AddTask(temp);
				else if(temp[0].equals("-"))
					//RemoveTask(temp);
					;
				else if(temp[0].equals("mod"))
					//ModifyTask(temp);
					;
				else if(temp[0].equals("view"))
					//ViewTask(temp);
					;
				else if(temp[0].equals("search"))
					//SearchTask(temp);
					;
				else if(temp[0].equals("done"))
					//DoneTask(temp);
					;
				else
					output.add("Command error!");
				
				output.add("Complete."); //this is for testing
	}
	
    //pass Object with statements to be displayed to GUI
    public static ArrayList<String> out(){
    	return output;
    	
    }
    
    //print to console instead
    public static void out2console(){
    	int size = output.size();
        
		 for(int i = 0; i < size ; i++){
			 //output.add(size);
			 String astr = output.get(i);
			 System.out.println(astr);
		 }
		 output.clear();
    }
    
	
	/*end of modification - defeng, may 27
	 */
	
	public static void AddTask(String[] item) {
		
		int i=0,j=0,k=0;
		char[] temp;
		String TaskDescription="";
		String tempWord="";
		
		if(item[0].equals("+*")) {
			Importance = true;
			if(Importance)
				output.add("Importance Stored.");
		}
		
		for(j=0; j<item.length; j++) {
			temp = item[j].toCharArray();
			//System.out.println("convert to char"+temp[0]);
			if(temp[0] == '#') {
				k=1;
				tempWord="";
				while(k<temp.length) {
					tempWord = tempWord + temp[k];
					k++;
				}
				System.out.println(tempWord+" call store date");
				StoreDate(tempWord);
			}
			if(temp[0] == '@') {
				k=1;
				tempWord="";
				while(k<temp.length) {
					if(temp[k] == '-') {
						System.out.println(tempWord+" call store start time");
						StoreStartTime(tempWord);
						tempWord = "";
						k++;
					}
					tempWord = tempWord + temp[k];
					k++;
				}
				System.out.println(tempWord+" call store duetime");
				StoreDueTime(tempWord);
			}
			if(temp[0] == '$') {
				k=1;
				tempWord="";
				while(k<temp.length) {
					tempWord = tempWord + temp[k];
					k++;
				}
				System.out.println(tempWord+" call store venue");
				StoreVenue(tempWord);
			}
			if(temp[0] == ':') {
				k=1;
				tempWord="";
				while(k<temp.length) {
					tempWord = tempWord + temp[k];
					k++;
				}
				System.out.println(tempWord+" call store label");
				StoreLabel(tempWord);
			}
			if(temp[0] == '*') {
				System.out.println("Importance stored");
			}
			if(temp[0]!='*' && temp[0]!='#' && temp[0]!='@' && temp[0]!='$' && temp[0]!='+' && temp[0]!=':') {
				TaskDescription = TaskDescription + item[j]+' ';
				//System.out.println(TaskDescription+"TaskDes");
			}
		}
		StoreTaskDescription(TaskDescription); //store the task description
	}
	
	
	public static void StoreTaskDescription(String task) {
		output.add(task+" task");
		// call for Store task description here
	}
	public static void StoreStartTime(String time) {
		//output.add(time+" <start time"); //this is for testing
		int IntTime=0;
		int k=3;
		char[] charTime;
		
		charTime = time.toCharArray();
		for(int i=1; i<=1000; i*=10) {
			IntTime = IntTime + (charTime[k--]-48)*i;
		}
		output.add(IntTime+" <StartTime");
		// call for Store start time here (in Int format)
	}
	public static void StoreDueTime(String time) {
		//output.add(time+" <due time"); //this is for testing
		int IntTime=0;
		int k=3;
		char[] charTime;
		
		charTime = time.toCharArray();
		for(int i=1; i<=1000; i*=10) {
			IntTime = IntTime + (charTime[k--]-48)*i;
		}
		output.add(IntTime+" <DueTime");
		// call for due time here (in Int format)
	}
	public static void StoreVenue(String venue) {
		output.add(venue+" <venue");
		// call for Store venue here
	}
	public static void StoreLabel(String label) {
		output.add(label+" <label");
		// call for Store label here
	}
	public static void StoreDate(String date) {
		output.add(date+" <date");
		int IntDate=0;
		int k=5;
		char[] ddmmyy;
		
		ddmmyy = date.toCharArray();
		for(int i=1; i<=100000; i*=10) {
			IntDate = IntDate + (ddmmyy[k--]-48)*i;
		}
		output.add(IntDate+" <IntDate");
		// call for Store date here (in Int format)
	}
}